<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page 
  language="java"
  contentType="text/html; charset=ISO-8859-1"
  import				="com.epro.standard.frontend.util.FileInfoUtil,
                      java.util.Vector,
                      java.util.Date,
                      java.text.SimpleDateFormat,
                      java.util.Locale,
                      com.softplus.carrefour.hd.bltier.admin.ICFHDSystemViewer,
                      com.softplus.carrefour.hd.bltier.admin.CFHDSystemManage,
                      com.softplus.carrefour.hd.CFHDSystem,
                      com.softplus.carrefour.hd.bltier.admin.ICFHDModuleViewer,
                      com.softplus.carrefour.hd.bltier.admin.CFHDModuleManage,
                      com.softplus.carrefour.hd.bltier.admin.ICountryViewer,
                      com.softplus.carrefour.hd.bltier.admin.CountryManage,
                      com.softplus.carrefour.hd.bltier.entity.*,
                      com.softplus.carrefour.hd.bltier.entity.Country,
 					  com.softplus.carrefour.hd.bltier.entity.UserAccount,
					 com.softplus.carrefour.hd.bltier.util.DateUtil,
					 com.softplus.carrefour.hd.bltier.admin.IUserLevelViewer,
					 com.softplus.carrefour.hd.bltier.admin.UserLevelManage                     
                     "
%>

<HTML xmlns:epro>
<%@  taglib uri="/WEB-INF/HeadTag.tld" prefix="head"%>  
<%@  taglib uri="/WEB-INF/TextfieldTag.tld" prefix="textfield"%>
<%@ taglib uri="/WEB-INF/CalendarTag.tld" prefix="calendar"%>
<%@ taglib uri="/WEB-INF/ErrorTag.tld" prefix="error"%>
<head:Head
	author="Pomme" 
  import="calendar,textfield,error"
  jsFile="../script/spTitleRefresh.js,../script/checkValidData.js,../script/convertDataType.js,../script/dateCalendar.js,../script/Alert.js" 
	styleFile="../theme/defaultTheme.css,../theme/CFRLTheme.css" 
	title="List of Cases Still Open for More Than X Day(s)">
</head:Head>
   <%@include file="../include/spUserVOInclude.jsp"%>
<%  
		System.out.println("==============================CFHDRPMT01=======================");

		String selectWidth		= "500";
//-=========================		    
		SimpleDateFormat	simpDF	=	new SimpleDateFormat("dd/MM/yyyy");
		UserAccount					userVO2					=  (UserAccount) session.getAttribute("userVO");//"kunlaporn_c";
		String								userID					    = userVO2.getUserId();//request.getParameter("uid");
		 IUserLevelViewer       ulViwer                      = (UserLevelManage)CFHDSystem.getControlClass("USER_LEVEL");
         String                              uLevel                       = ulViwer.getUserLevelByUserID(userID)==null?"":ulViwer.getUserLevelByUserID(userID);	
                    if(uLevel.equals("")){
                        out.println("<script src=\"../script/Alert.js\" type=\"text/javascript\"></script>");
                        out.println("<script type=\"text/javascript\">");
                        out.println("if(showOInfoDialog(\"Authentication Failed!\", \"You might not be authorized in E-Helpdesk System. Please Contact Administrator.\\n click OK  to continue.\", \"OK\" )){");
                        out.println("  parent.location =parent.location; ");
                        out.println(" } \n </script>");                     
                    }          
       
	//-=========================		    
		    
    FileInfoUtil	fileInfoUtil 			= (session.getAttribute("fileInfoUtil")!=null?(FileInfoUtil) session.getAttribute("fileInfoUtil"):new FileInfoUtil());
    fileInfoUtil.setMenuIDCode("CFHDRPMT01 ") ;
    fileInfoUtil.setMenuName("List of Cases by Type and Status") ;
    fileInfoUtil.setMenuDesc("To list the cases by specified type and status") ;
    fileInfoUtil.setMasterWording("List of Cases by Type and Status") ;
    
    String backURL			= "/CFRL/CFRLWEBMN01.jsp" ;
    String backClick		= "window.location='" + backURL + "'" ; 
       
    // === define object ===
			ICountryViewer					countryManage	=	(CountryManage)CFHDSystem.getControlClass("COUNTRY");
    // === define vector ===
			Vector	countryVector	=	new Vector(0);
         
    //Current Date
    Date d = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
    String currentDate = formatter.format(d);   
    String current = currentDate.toString();
    System.out.println("======================CurrentDate========================== :" + currentDate);
    
%>
  <body >  
    <%=fileInfoUtil.MasterHeadTable()%>
    <script src="../script/spToolbar.js" type="text/javascript"></script>
<FORM name="frm">
<INPUT type="hidden" name="hiddenDate" value=<%=currentDate%>>
<TABLE align="center" border="0" width="100%" cellpadding="0" cellspacing="0">
        <TR>
          <TD valign="top" align="left" style="padding-left:15px;">
            <IMG SRC= "../images/icon/toolbar/nBackToMenu.gif" alt="Back To Menu" onclick="backTomenu();" Style="cursor:hand"
              onmouseover="Javascript: this.src='../images/icon/toolbar/oBackToMenu.gif' " 
              onmouseout="Javascript: this.src='../images/icon/toolbar/nBackToMenu.gif' ">   
	<!--a href="../../CFRL/CFRLWEBMN01.jsp">
		<img alt="Back to view all cases" src="../images/icon/toolbar/nBackToMenu.gif" width="21" height="21" border="0" onmouseout="imgOut(this)" onmouseover="imgOver(this)" /></a-->
                 
          </TD>
        </TR>
</TABLE>

<TABLE align="center" border="0" bordercolor="red" cellpadding="1" cellspacing="1">
	<TR>
		<TD class="titleFont">Open Case Country : </TD>
		<TD colspan="3">
	<%
  if(uLevel.equals(UserLevel.ADMIN) || uLevel.equals(UserLevel.LEVEL_2_AMS_ZONE_ASIA) || uLevel.equals(UserLevel.LEVEL_3_AMS_BANGKOK) || uLevel.equals(UserLevel.PRODUCTION_STAFF))
    {
	%>
      <SELECT name="country" style="width: 220px" >
      <OPTION value="ALL">All</OPTION>
		
    <% 
				countryVector	=	countryManage.getAllCountry();
				if (countryVector != null)
				{		for (int m=0;m<countryVector.size();m++)
						{		
              Country	countryEntity	=	(Country)countryVector.elementAt(m);
              
 		%>
                <OPTION value="<%=countryEntity.getCountryId()%>"><%=countryEntity.getCountryName()%></OPTION>
		<%}%>
	<%}%>
			</SELECT>
	<%}else{%>
      <SELECT name="country" style="width: 220px" >
      <OPTION value="<%=userVO2.getCountry().getCountryId()%>"><%=userVO2.getCountry().getCountryName()%></OPTION>
	  </SELECT>
	<%}%>
		</TD>
	</TR>
	<TR>
		<TD class="titleFont">
      Case Type : 
    </TD>
		<TD class="titleNormal">
      <INPUT type="checkbox" name="P1" value="P1"> User Question(P1)      
    </TD>
	</TR>
	<TR>
		<TD></TD>
		<TD class="titleNormal">
      <INPUT type="checkbox" name="P2" value="P2"> Problem Report(P2)
    </TD>
	</TR>
	<TR>
		<TD></TD>
		<TD class="titleNormal">
      <INPUT type="checkbox" name="P3" value="P3"> Change Request(P3)
    </TD>
	</TR>	
	<TR>
		<TD></TD>
		<TD class="titleNormal">
      <INPUT type="checkbox" name="P4" value="P4"> Service Request(P4)
    </TD>
	</TR>		
	<TR>
		<TD class="titleFont">
      Status:
    </TD>
		<TD>  
        <INPUT type="checkbox" name="Validated" value="<%=CfhdCaseHead.STATUS_VALIDATED%>"> Validated      
    </TD>
		<TD  colspan="2">
        <INPUT type="checkbox" name="Close" value="<%=CfhdCaseHead.STATUS_CLOSE%>"> Close      
		 </TD>
	</TR>
 	<TR>
		<TD >
      </TD>
		<TD>  
        <INPUT type="checkbox" name="Submitted" value="<%=CfhdCaseHead.STATUS_SUBMITTED%>"> Submitted      
    </TD>
		<TD colspan="2" >
        <INPUT type="checkbox" name="Rejected" value="<%=CfhdCaseHead.STATUS_REJECTED%>"> Rejected      
		 </TD>
	</TR>
 	<TR>
		<TD >
      </TD>
		<TD>  
        <INPUT type="checkbox" name="Finished" value="<%=CfhdCaseHead.STATUS_FINISH%>"> Finished      
    </TD>
		<TD colspan="2">
        <INPUT type="checkbox" name="Cancelled" value="<%=CfhdCaseHead.STATUS_CANCEL%>"> Cancelled      
		 </TD>
	</TR>
	<TR>
		<TD >
      </TD>
		<TD>  
        <INPUT type="checkbox" name="Approved" value="<%=CfhdCaseHead.STATUS_APPROVE%>"> Approved      
    </TD>
		<TD colspan="2">
        <INPUT type="checkbox" name="Unattended" value="<%=CfhdCaseHead.STATUS_UNATTEND%>"> Unattended      
		 </TD>
	</TR>
  <TR>
		<TD class="titleFont">Open Case Date </TD>
	</TR>
 	<TR>
		<TD class="titleFont">From : </TD>
		<TD><textfield:textfield  value="<%=simpDF.format(DateUtil.getLocalDate(userID))%>"  name="fromDate" readonly="yes" dataType="date" label1="From Date" label2="To Date" isBetween="yes" firstValue="yes"
														compareWith="toDate" condition="<="></textfield:textfield>
					<IMG src="../images/icon/calendar/nCalendar.gif" onmouseover="this.src='../images/icon/calendar/oCalendar.gif'"
								onmouseout="this.src='../images/icon/calendar/nCalendar.gif'" alt="Calendar" style='cursor: hand' onclick="CalendarFromDate()"> </TD>
		<TD class="titleFont">To : </TD>
		<TD><textfield:textfield  value="<%=simpDF.format(DateUtil.getLocalDate(userID))%>"  name="toDate" readonly="yes" dataType="date" label1="From Date" label2="To Date" isBetween="yes" firstValue="no"
														compareWith="fromDate" condition="<=" ></textfield:textfield>
					<IMG src="../images/icon/calendar/nCalendar.gif" onmouseover="this.src='../images/icon/calendar/oCalendar.gif'"
								onmouseout="this.src='../images/icon/calendar/nCalendar.gif'" alt="Calendar" style='cursor: hand' onclick="CalendarToDate()"> </TD>
	</TR>
  
  <TR>
    <TD></TD>
    <TD align="center">     
    </TD>
  </TR>    
  </TABLE>    
  <TABLE align="center" border="0" bordercolor="red" cellpadding="0" cellspacing="0" width="100%" >
    <BR>
    <TR>
      <TD class="titleFont" >
      <center>
       <INPUT type="button" value="View Report" onclick="checkCaseTypeandStatus()">
         <INPUT type="button" value="Export To Excel" onclick="checkCaseTypeandStatustoExcel()">
      </center>
  <BR>
<FONT  color="red" >
        *Please Note: To display report in the correct format,
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <BR>please select 'Open' button to view report 
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <BR>before save it as an excel file
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 </FONT>
      </TD>
    </TR>     
  </TABLE>
</FORM>

<SCRIPT language="javascript">
  function CalendarFromDate()
	{
		document.all.fromDate.focus();
		document.all.fromDate.value = window.showModalDialog('Calendar.jsp','window ','status:no;dialogHeight:231px;dialogWidth:262px;scroll:no');	
		if(document.all.fromDate.value == "undefined")
		{	showOWarningDialog("warning","<B>Please Input Open Case Date From again","OK");
			document.all.fromDate.value='';}
        else {document.all.fromDate.focus();}
	}
  
	function CalendarToDate()
	{		
		document.all.toDate.value = window.showModalDialog('Calendar.jsp','window ','status:no;dialogHeight:231px;dialogWidth:262px;scroll:no');	
		if(document.all.toDate.value == "undefined")   
		{		document.all.toDate.value = "";
				showOWarningDialog("warning","<B>Please Input Open Case Date To again","OK");
				document.all.toDate.focus();				
		}
		else {document.all.toDate.focus();}
	}
  
  function ViewReport()
  {     
   if(frm.fromDate.value == "")
   {
    var current = frm.hiddenDate.value;
    //alert(current);
    //frm.fromDate = current;    
   }
   
 //  alert(frm.Validated.checked);
         
  //        alert(frm.fromDate.value);
 //         alert(frm.toDate.value);
          
       
    var url = "CFHDRPRP01.jsp?Country=" + frm.country.value + 
    "&P1=" + frm.P1.checked + "&P2=" + frm.P2.checked + "&P3=" + frm.P3.checked + "&P4=" + frm.P4.checked + 
    "&Validated=" + frm.Validated.checked + "&Close=" + frm.Close.checked + "&Submitted=" + frm.Submitted.checked +   
    "&Rejected=" + frm.Rejected.checked + "&Finished=" + frm.Finished.checked + "&Cancelled=" + frm.Cancelled.checked + "&Approved=" + frm.Approved.checked +"&Unattended=" + frm.Unattended.checked +
   "&From=" + frm.fromDate.value + "&To=" + frm.toDate.value;
    window.location.href = url;
  }
  function backTomenu()
  {    
    <%= backClick%> ;
  }
  function checkCaseTypeandStatus(){
  if (   ( frm.P1.checked==false )&&( frm.P2.checked==false )&&( frm.P3.checked==false )&&( frm.P4.checked==false ))
   {    showOWarningDialog("warning","<B>Please Select Case Type","OK");
   }
   else{
           if (   ( frm.Validated.checked==false )&&( frm.Close.checked==false )&&( frm.Submitted.checked==false )&&
                  ( frm.Rejected.checked==false )&&( frm.Finished.checked==false )&&( frm.Cancelled.checked==false )&&   ( frm.Approved.checked==false ) &&  ( frm.Unattended.checked==false )
              )
              {    showOWarningDialog("warning","<B>Please Select Status","OK");  }
             else{  
                         if(document.all.fromDate.value == ""){showOWarningDialog("warning","<B>Please Specify Open Case Date From","OK");  }
                         else{   
                                   if(document.all.toDate.value == ""){showOWarningDialog("warning","<B>Please Specify Open Case Date To","OK");  }
                                   else{ViewReport();    }
                                 }
                         
                    }   
   
        }
 }

  function ViewReporttoExcel()
  {     
   if(frm.fromDate.value == "")
   {
    var current = frm.hiddenDate.value;
    //alert(current);
    //frm.fromDate = current;    
   }
   
 //  alert(frm.Validated.checked);
         
  //        alert(frm.fromDate.value);
 //         alert(frm.toDate.value);
          
       
    var url = "CFHDRPRP01_excel.jsp?Country=" + frm.country.value + 
    "&P1=" + frm.P1.checked + "&P2=" + frm.P2.checked + "&P3=" + frm.P3.checked + "&P4=" + frm.P4.checked + 
    "&Validated=" + frm.Validated.checked + "&Close=" + frm.Close.checked + "&Submitted=" + frm.Submitted.checked +   
    "&Rejected=" + frm.Rejected.checked + "&Finished=" + frm.Finished.checked + "&Cancelled=" + frm.Cancelled.checked + "&Approved=" + frm.Approved.checked +"&Unattended=" + frm.Unattended.checked +
   "&From=" + frm.fromDate.value + "&To=" + frm.toDate.value;
   window.open(url);
   // window.location.href = url;
  }
  function backTomenu()
  {    
    <%= backClick%> ;
  }
  function checkCaseTypeandStatustoExcel(){
  if (   ( frm.P1.checked==false )&&( frm.P2.checked==false )&&( frm.P3.checked==false )&&( frm.P4.checked==false ))
   {    showOWarningDialog("warning","<B>Please Select Case Type","OK");
   }
   else{
           if (   ( frm.Validated.checked==false )&&( frm.Close.checked==false )&&( frm.Submitted.checked==false )&&
                  ( frm.Rejected.checked==false )&&( frm.Finished.checked==false )&&( frm.Cancelled.checked==false )&&   ( frm.Approved.checked==false ) &&  ( frm.Unattended.checked==false )
              )
              {    showOWarningDialog("warning","<B>Please Select Status","OK");  }
             else{  
                         if(document.all.fromDate.value == ""){showOWarningDialog("warning","<B>Please Specify Open Case Date From","OK");  }
                         else{   
                                   if(document.all.toDate.value == ""){showOWarningDialog("warning","<B>Please Specify Open Case Date To","OK");  }
                                   else{ViewReporttoExcel();    }
                                 }
                         
                    }   
   
        }
 }
  
   function nonUserLevel()
  {   
 	if(showOInfoDialog("Authentication Failed!", "You might not authorized in Report System. Please Contact Administrator.\n click OK  to continue.", "OK" )){
   <%= backClick%> ;
   // onload="if('<%//=uLevel%>'==''){nonUserLevel();}"
   }
  } 
</SCRIPT>    
    <%=fileInfoUtil.MasterFootTable()%>
   </body>
   <%@include file="../include/eproErrorAlert.jsp"%>
</HTML>
